package com.example.pjy.mapper;

import com.example.pjy.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface StudentMapper {

    //新增
    @Insert("insert into student (studentId,sname,sgrade,major,create_time,update_time,status)" +
            "values(#{studentId},#{sname},#{sgrade},#{major},#{createTime},#{updateTime},#{status})")
    void add(Student student);



    //查询所有
    @Select("select * from student")
    List<Student> list();


    //根据id查询
    @Select("select * from student where studentId = #{studentId}")
    Student findById(Integer studentId);




    //更新
    @Update("update student set studentId=#{studentId},sname=#{sname},sgrade=#{sgrade},major=#{major},status=#{status},update_time=#{updateTime} where studentId=#{studentId}")
    void updatest(Student student);




    //删除
    @Delete("delete from student where studentId=#{studentId}")
    void delete(Integer studentId);




    //查询是否有相同学号
    @Select("select count(*)>0 from student where studentId = #{studentId}")
    boolean isExist(Integer studentId);


    //查询是否还有总成绩管理的记录
    @Select("select count(*)>0 from totalScore where studentId = #{studentId}")
    boolean isTotalScoreExist(Integer studentId);


    @Select("select * from student where sname like concat ('%',#{keyword},'%')")
    List<Student> selectbyname(String keyword);
}
